//
//  SelectPop.m
//  ChampoinPeso
//
//  Created by mac on 2025/2/20.
//

#import "SelectPop.h"
#import "WMZDialog.h"
#import "SelectAddress.h"
#import "SelectDate.h"
#import "SelectOne.h"
#import "BRStringPickerView.h"
#import "InfoVerify.h"
#import "Logout.h"
#import "Account.h"

static SelectPop *util = nil;
@interface SelectPop()

{
    WMZDialog *myAlert;
}
@property (nonatomic,strong)SelectAddress *address;
@property (nonatomic,strong)NSArray<BRResultModel *> *resultModelArr;
@end
@implementation SelectPop
+(instancetype)getInstance
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        util = [[SelectPop alloc]init];
    });
    return util;
}

-(void)dateSelect
{
//    MJWeakSelf
    myAlert =
    Dialog()
    .wCustomMainViewSet(^(UIView *mainView) {
    })
    .wHeightSet(354)
    .wTypeSet(DialogTypeMyView)
    .wWidthSet(SCREEN_WIDTH)
    .wShowAnimationSet(AninatonShowNone)
    .wHideAnimationSet(AninatonHideTop)
    .wMainToBottomSet(YES)
    .wShadowCanTapSet(YES)
    .wShadowShowSet(YES)
    .wMyDiaLogViewSet(^UIView *(UIView *mainView) {
        mainView.backgroundColor = UIColor.clearColor;
        SelectDate *view = [[SelectDate alloc]initWithFrame:CGRectZero];
        [mainView addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.bottom.mas_offset(0);
        }];
        view.closeAction = ^{
            dispatch_async(dispatch_get_main_queue(), ^{
                [self->myAlert closeView];
            });
        };
        view.dateCommitAction = ^(NSString * _Nonnull str) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [self->myAlert closeView];
                if (self.dateCommitAction) {
                    self.dateCommitAction(str);
                }
            });
        } ;
        
        return nil;
    })
    .wStart();
}


-(void)citySelect:(NSDictionary*)source name:(nonnull NSString *)name
{
    //    MJWeakSelf
    myAlert =
    Dialog()
        .wCustomMainViewSet(^(UIView *mainView) {
        })
        .wHeightSet(354)
        .wTypeSet(DialogTypeMyView)
        .wWidthSet(SCREEN_WIDTH)
        .wShowAnimationSet(AninatonShowNone)
        .wHideAnimationSet(AninatonHideTop)
        .wMainToBottomSet(YES)
        .wShadowCanTapSet(YES)
        .wShadowShowSet(YES)
        .wMyDiaLogViewSet(^UIView *(UIView *mainView) {
            mainView.backgroundColor = UIColor.clearColor;
            SelectAddress *view = [[SelectAddress alloc]initWithFrame:CGRectZero ];
            view.pView.backgroundColor = UIColor.clearColor;
            [mainView addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.left.right.bottom.mas_offset(0);
            }];
            [view setSource:source name:name];
            view.closeAction = ^{
                [self->myAlert closeView];
            };
            view.dddressCommitAction = ^(NSArray<BRResultModel *> * _Nonnull resultModelArr) {
                [self->myAlert closeView];
                if (self.addressCommitAction) {
                    self.addressCommitAction(resultModelArr)
                    ;
                }
            };
            return nil;
        })
        .wStart();
    }



-(void)oneSelect:(InfoModel *)model key:(int)index{
    myAlert =
    Dialog()
    .wCustomMainViewSet(^(UIView *mainView) {
    })
    .wHeightSet(354)
    .wTypeSet(DialogTypeMyView)
    .wWidthSet(SCREEN_WIDTH)
    .wShowAnimationSet(AninatonShowNone)
    .wHideAnimationSet(AninatonHideTop)
    .wMainToBottomSet(YES)
    .wShadowCanTapSet(YES)
    .wShadowShowSet(YES)
    .wMyDiaLogViewSet(^UIView *(UIView *mainView) {
        mainView.backgroundColor = UIColor.clearColor;
        SelectOne *view = [[SelectOne alloc]initWithFrame:CGRectZero];
        [mainView addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.bottom.mas_offset(0);
        }];
        [view setSource:model andkey:index];
        view.closeAction = ^{
            [self->myAlert closeView];
        };
        view.commitAction = ^(BRResultModel * _Nonnull model) {
            [self->myAlert closeView];
            if (self.commitAction) {
                self.commitAction(model);
            }
        };
        return nil;
    })
    .wStart();

}


-(void)logOut{
    myAlert =
    Dialog()
    .wCustomMainViewSet(^(UIView *mainView) {
    })
    .wHeightSet(400)
    .wTypeSet(DialogTypeMyView)
    .wWidthSet(SCREEN_WIDTH)
    .wShowAnimationSet(AninatonShowNone)
    .wHideAnimationSet(AninatonHideTop)
    .wShadowCanTapSet(YES)
    .wShadowShowSet(YES)
    .wMyDiaLogViewSet(^UIView *(UIView *mainView) {
        mainView.backgroundColor = UIColor.clearColor;
        Logout *view = [[Logout alloc]initWithFrame:CGRectZero];
        [mainView addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.bottom.mas_offset(0);
        }];
        view.closeAction = ^{
            [self->myAlert closeView];
            if (self.logoutCommitAction) {
                self.logoutCommitAction();
            }

        };
        view.commitAction = ^{
            [self->myAlert closeView];

        };
        return nil;
    })
    .wStart();
}

-(void)accountCancellation
{
    myAlert =
    Dialog()
    .wCustomMainViewSet(^(UIView *mainView) {
    })
    .wHeightSet(450)
    .wTypeSet(DialogTypeMyView)
    .wWidthSet(SCREEN_WIDTH)
    .wShowAnimationSet(AninatonShowNone)
    .wHideAnimationSet(AninatonHideTop)
    .wShadowCanTapSet(YES)
    .wShadowShowSet(YES)
    .wMyDiaLogViewSet(^UIView *(UIView *mainView) {
        mainView.backgroundColor = UIColor.clearColor;
        Account *view = [[Account alloc]initWithFrame:CGRectZero];
        [mainView addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.bottom.mas_offset(0);
        }];
        view.closeAction = ^{
            dispatch_async(dispatch_get_main_queue(), ^{
                [self->myAlert closeView];
            });
            if (self.accountCommitAction) {
                self.accountCommitAction();
            }
        };
        view.commitAction = ^{
            dispatch_async(dispatch_get_main_queue(), ^{
                [self->myAlert closeView];
            });
        };
        view.toastAction = ^{
            if (self.tAction) {
                self.tAction();
            }
        };
        return nil;
    })
    .wStart();

}

@end
